import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_bmfmap_example/pages/homepage/pages/Equipment_message/tool/tool.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart';

class evaluationAll extends StatefulWidget {
  evaluationAll({Key key, this.id}) : super(key: key);

  var id;

  @override
  _evaluationAllState createState() => _evaluationAllState();
}

class _evaluationAllState extends State<evaluationAll> {
  var resulte;

  @override
  void initState() {
    // TODO: implement initState

    super.initState();
    _getinformation();
  }

  _getinformation() async {
    EasyLoading.show(status: '加载中...');
    var resultevaluation = await Http.get(
            '/evaluate/getEvaluateByCommodityId?commodityId=' +
                widget.id.toString())
        .catchError((value) {
      Fluttertoast.showToast(msg: "服务器异常");
      EasyLoading.dismiss();
    });

    EasyLoading.dismiss();
    resulte = resultevaluation;
    print("**************************");
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('全部评价'),
        backgroundColor: Colors.blue,
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Container(
          decoration: new BoxDecoration(
              color: Colors.white,
              borderRadius: new BorderRadius.circular((16.0)),
              boxShadow: [
                BoxShadow(
                    color: Colors.black12,
                    offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                    blurRadius: 5.0, //阴影模糊程度
                    spreadRadius: 2 //阴影扩散程度
                    )
              ]),
          child: Padding(
            padding: const EdgeInsets.only(
                left: 16.0, top: 2, right: 16, bottom: 20),
            child: Column(
              children: [
                Center(
                    // height: 12,
                    child: resulte == null
                        ? Container()
                        : Column(
                            children: evaluationList(),
                          )),
              ],
            ),
          ),
        ),
      ),
    );
  }

  evaluationList() {
    List<Widget> evaluationL = [];
    for (var i = 0; i < resulte.length; i++) {
      evaluationL.add(evaluation(resulte[i]));
    }
    return evaluationL;
  }

  evaluation(var listOnly) {
    return Container(
      padding: const EdgeInsets.all(2.0),
      child: Column(
        children: [
          Container(
              margin: const EdgeInsets.all(2.0),
              // color: Color.fromRGBO(256, 256, 256, 0.1),
              width: 330,
              child: Column(children: [
                Row(children: [
                  Container(
                    margin: const EdgeInsets.only(
                        left: 5, right: 10, top: 10, bottom: 10),
                    child: ClipOval(
                      child: Image.network(
                        listOnly['portrait'],
                        width: 38,
                        height: 38,
                      ),
                    ),
                  ),
                  Column(children: [
                    Container(width: 200, child: Text(listOnly['username'])),
                    Container(
                        width: 200,
                        child: Text(
                          Tool.getTime(listOnly['created']),
                          style: TextStyle(
                            color: Colors.black54,
                            fontSize: 14,
                          ),
                        ))
                  ]),
                ]),
                Container(
                  // margin: const EdgeInsets.all(4.0),
                  width: 320,
                  child: Text(listOnly['info']),
                ),
                Container(
                  width: 500,
                  // constraints: BoxConstraints(maxWidth: 500),
                  margin: const EdgeInsets.all(4.0),
                  child: Row(
                    children: [
                      if (listOnly['imgurl1'] != null)
                        Container(
                          margin: const EdgeInsets.all(2.0),
                          child: Image.network(listOnly['imgurl1'],
                              fit: BoxFit.contain, width: 75),
                        ),
                      if (listOnly['imgurl2'] != null)
                        Container(
                          margin: const EdgeInsets.all(2.0),
                          child: Image.network(listOnly['imgurl2'],
                              fit: BoxFit.contain, width: 75),
                        ),
                      if (listOnly['imgurl3'] != '')
                        Container(
                          margin: const EdgeInsets.all(2.0),
                          child: Image.network(listOnly['imgurl3'],
                              fit: BoxFit.contain, width: 75),
                        ),
                      if (listOnly['imgurl4'] != '')
                        Container(
                          margin: const EdgeInsets.all(2.0),
                          child: Image.network(listOnly['imgurl4'],
                              fit: BoxFit.contain, width: 75),
                        ),
                    ],
                  ),
                ),
              ])),
          Divider(
            height: 10.0,
            indent: 0.0,
            color: Colors.black38,
          ),
        ],
      ),
    );
  }
}
